// const arr = ['/a/b/c','/c/1','/c','/c/1/2','/a/b','/','/a','/b/1']
// const path = '/c/1/2'

// let a = path.split('/').map((r) => (r === '/' ? '/' : '/' + r))
// console.log(a)
// function getTotalTail(baseArr){
//     let setArr = []
//     let currNum = ''
//     baseArr.forEach((item, index) => {
       
//       if(index == 0){
//         setArr.push(baseArr[index])
//       }else{
        
//         if(currNum){
//           currNum = currNum + baseArr[index]
          
//         }else{
//           currNum = baseArr[index]
//         }
//         setArr.push(currNum);
        
//       }
//     })
//     return setArr
// }


// let c = getTotalTail(a)
// console.log(c)
const fn = (source)=>{
    let res = []
    source.forEach(el=>{
        res.push(el)
        el.children && res.push(...fn(el.children))
    })
    return res
}


  let arr = [{title:'a',children:[{title:'a-a'}]},{title:'b'}]
  console.log(fn(arr))